package com.wuage.infrastructure.security;

import com.wuage.infrastructure.status.BizResultCode;
import com.wuage.infrastructure.utils.OpenGsonWrapper;
import com.wuage.infrastructure.utils.Response;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.Serializable;

/**
 * @author Shynin
 * @version 1.0
 * @date 2020-09-03 00:20
 */
public class JwtAuthenticationEntryPoint implements AuthenticationEntryPoint, Serializable {
    private static final long serialVersionUID = 1L;

    @Override
    public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException e)
            throws IOException {
        response.setCharacterEncoding("UTF-8");
        response.setContentType("application/json; charset=utf-8");
        response.getWriter().write(OpenGsonWrapper.toJson(new Response<>(BizResultCode.UN_LOGIN)));
    }
}
